package com.ruoyi.edu.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edu.domain.EduAuxcouse;
import com.ruoyi.edu.service.IEduAuxcouseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程管理Controller
 * 
 * @author 张聪
 * @date 2023-05-08
 */
@Controller
@RequestMapping("/edu/auxcouse")
public class EduAuxcouseController extends BaseController
{
    private String prefix = "edu/auxcouse";

    @Autowired
    private IEduAuxcouseService eduAuxcouseService;

    @RequiresPermissions("edu:auxcouse:view")
    @GetMapping()
    public String auxcouse()
    {
        return prefix + "/auxcouse";
    }

    /**
     * 查询课程管理列表
     */
    @RequiresPermissions("edu:auxcouse:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduAuxcouse eduAuxcouse)
    {
        startPage();
        List<EduAuxcouse> list = eduAuxcouseService.selectEduAuxcouseList(eduAuxcouse);
        return getDataTable(list);
    }

    /**
     * 导出课程管理列表
     */
    @RequiresPermissions("edu:auxcouse:export")
    @Log(title = "课程管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduAuxcouse eduAuxcouse)
    {
        List<EduAuxcouse> list = eduAuxcouseService.selectEduAuxcouseList(eduAuxcouse);
        ExcelUtil<EduAuxcouse> util = new ExcelUtil<EduAuxcouse>(EduAuxcouse.class);
        return util.exportExcel(list, "课程管理数据");
    }

    /**
     * 新增课程管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程管理
     */
    @RequiresPermissions("edu:auxcouse:add")
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduAuxcouse eduAuxcouse)
    {
        //添加课程的时候将当前登录的教师id获取并且设置
        eduAuxcouse.setTid(getUserId());
        return toAjax(eduAuxcouseService.insertEduAuxcouse(eduAuxcouse));
    }

    /**
     * 修改课程管理
     */
    @RequiresPermissions("edu:auxcouse:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        EduAuxcouse eduAuxcouse = eduAuxcouseService.selectEduAuxcouseById(id);
        mmap.put("eduAuxcouse", eduAuxcouse);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程管理
     */
    @RequiresPermissions("edu:auxcouse:edit")
    @Log(title = "课程管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduAuxcouse eduAuxcouse)
    {
        return toAjax(eduAuxcouseService.updateEduAuxcouse(eduAuxcouse));
    }

    /**
     * 删除课程管理
     */
    @RequiresPermissions("edu:auxcouse:remove")
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduAuxcouseService.deleteEduAuxcouseByIds(ids));
    }
}
